<template>
  <!-- 引入container布局 -->
  <el-container class="home-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../assets/logo.jpg" alt />
        <span>个人运动平台</span>
      </div>
      <el-button type="info" @click="logout">安全退出</el-button>
    </el-header>

    <!-- 主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse?'64px':'200px'">
          <div class="toggle-button" @click="toggleCollapase">|||</div>
        <el-menu background-color="#545c64" text-color="#fff" active-text-color="#409eff" 
        unique-opened :collapse="isCollapse" :collapse-transition="false" :router="true">
            <!-- 一级菜单 -->
          <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class="iconsObject[item.id]"></i>
              <span>{{item.title}}</span>
            </template>
            <el-menu-item :index="it.path" v-for ="it in item.sList" :key="it.id">
             <template slot="title">
              <i :class="iconsObject[item.id]"></i>
              <span>{{it.title}}</span>
             </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体内容 -->
      <el-main>
          <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
    data(){
        return{
            menuList:[],
            iconsObject: {
              '100':'el-icon-user-solid',
              '200':'el-icon-user-solid',
              '101':'el-icon-s-tools',
              '102':'el-icon-user-solid',
              '103':'el-icon-user-solid',
              '104':'el-icon-user-solid',
              '201':'el-icon-user-solid',
              '202':'el-icon-user-solid',
              '203':'el-icon-user-solid',
              '204':'el-icon-user-solid',
            },
            isCollapse:false
        }
    },
  created(){
      //查询menuList
      this.getMenuList();
  },
  methods: {
    logout() {
      window.sessionStorage.clear(); //清除session
      this.$router.push("/login");
    },
    //获取导航菜单方法
    async getMenuList(){
        const {data:res} = await this.$http.get("menus");
        console.log(res);
        if(res.flag !=200) return this.$message.error("获取列表失败！");
        this.menuList =res.menus;
    },
    //控制伸缩
    toggleCollapase(){
        this.isCollapse = !this.isCollapse;
    }
  },
};
</script>
<style scoped lang="less">
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0%;
  align-items: center;
  color: #fff;
  font-size: 20px;
  div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  background-color: #545c64;
  .el-menu{
      border-right: none;
  }
}
.el-main {
  background-color: #fff;
}
img {
  width: 55px;
  height: 55px;
}
.toggle-button{
    background-color: #4A5064;
    font-size: 10px;
    line-height: 24px;
    color:#fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;//显示小手
}
</style>em